﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using The_Chronicles_of_Asku.Areas.Tomb_Floors._1_10.ResourceFile;
using The_Chronicles_of_Asku.Characters;
namespace The_Chronicles_of_Asku.Areas.Tomb_Floors._1_10
{
    class FloorFour
    {
        Battle battle = new Battle();
        Skeleton skel = new Skeleton();
        Necromancer necro = new Necromancer();
        Undead zombie = new Undead();
        SetMobLevels setLevel = new SetMobLevels();
        Hero myHero = new Hero();
        Villager villager = new Villager();
        public bool complete = false;
      
        public void theFloor(Hero myHero, Mob mob)
        {
            setLevel.setMobLevelNine(skel, necro, zombie, villager);

            Console.WriteLine(FloorFourText.Entrance);
            ClearScreen();
            Console.WriteLine(FloorFourText.FirstRoomAttack);

            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            VillagerFight(myHero, villager);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            VillagerFight(myHero, villager);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);
            VillagerFight(myHero, villager);
            VillagerFight(myHero, villager);
            UndeadFight(myHero, zombie);
            UndeadFight(myHero, zombie);

            if (myHero.isAlive == true)
            {
                Console.WriteLine(FloorFourText.FirstRoomFinished);
                string firstRoomAnswer = Console.ReadLine();

                if (firstRoomAnswer == "1")
                {
                    Console.WriteLine(FloorFourText.ExploreFirstRoom);
                    ClearScreen();
                }

                else
                {
                    Console.WriteLine(FloorFourText.DontExploreFirstRoom);
                    ClearScreen();
                }
            }

            if (myHero.isAlive == true)
            {
                setLevel.setMobLevelTen(skel, necro, zombie, villager);

                Console.WriteLine(FloorFourText.SecondRoomAttack);

                UndeadFight(myHero, zombie);
                UndeadFight(myHero, zombie);
                UndeadFight(myHero, zombie);
                UndeadFight(myHero, zombie);
                VillagerFight(myHero, villager);
                VillagerFight(myHero, villager);
                VillagerFight(myHero, villager);
                UndeadFight(myHero, zombie);
                UndeadFight(myHero, zombie);
                UndeadFight(myHero, zombie);
                UndeadFight(myHero, zombie);
                VillagerFight(myHero, villager);
                VillagerFight(myHero, villager);
                VillagerFight(myHero, villager);
                UndeadFight(myHero, zombie);
                VillagerFight(myHero, villager);
                VillagerFight(myHero, villager);
                UndeadFight(myHero, zombie);
                VillagerFight(myHero, villager);
                VillagerFight(myHero, villager);
                UndeadFight(myHero, zombie);
                UndeadFight(myHero, zombie);
                UndeadFight(myHero, zombie);
                UndeadFight(myHero, zombie);
                VillagerFight(myHero, villager);

                if (myHero.isAlive == true)
                {
                    Console.WriteLine(FloorFourText.SecondRoomFinished);
                    string secondRoomAnswer = Console.ReadLine();

                    if (secondRoomAnswer == "1")
                    {
                        Console.WriteLine(FloorFourText.ExploreSecondRoom);
                        string chestAnswer = Console.ReadLine();
                        ClearScreen();

                        if (chestAnswer == "1")
                        {
                            Random rnd = new Random();
                            int gold = 0;
                            gold = rnd.Next(1, 101);
                            Console.WriteLine(FloorFourText.OpenChest, gold);
                            myHero.gold += gold;
                            if (myHero.gold >= myHero.goldCap)
                            {
                                myHero.gold = myHero.goldCap;
                            }
                            ClearScreen();
                        }

                        else
                        {
                            Console.WriteLine(FloorFourText.DontOpenChest);
                            ClearScreen();
                        }
                    }

                    else
                    {
                        Console.WriteLine(FloorFourText.DontExploreSecondRoom);
                    }
                }

                if (myHero.isAlive == true)
                {
                    Console.WriteLine(FloorFourText.End);
                    ClearScreen();
                    complete = true;
                }
            }

            if (myHero.isAlive == false)
            {
                Console.WriteLine(FloorFourText.Dead);
                myHero.isAlive = true;
            }
        }

        private void UndeadFight(Hero myHero, Undead zombie)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, zombie);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            zombie.ResetStats(zombie);

            Console.Clear();
        }

        private void SkeletonFight(Hero myHero, Skeleton skel)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, skel);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            skel.ResetStats(skel);

            Console.Clear();
        }

        private void NecromancerFight(Hero myHero, Necromancer necro)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, necro);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            necro.ResetStats(necro);

            Console.Clear();
        }

        private void VillagerFight(Hero myHero, Villager villager)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, villager);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            villager.ResetStats(villager);

            Console.Clear();
        }

        private void ClearScreen()
        {
            Console.ReadKey();
            Console.Clear();
        }
    }
}
